package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.SizeUtils;
import com.stark.customview.turntable.StkTextLineToCenterAdapter;
import com.stark.customview.turntable.StkTurnTableItem;
import com.stark.customview.turntable.StkTurnTableView;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.ApkBean;
import flc.ast.databinding.ActivityTurntableBinding;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.Content;
import stark.common.basic.utils.SPUtil;

public class TurntableActivity extends BaseAc<ActivityTurntableBinding> {

    private List<StkTurnTableItem> listData = new ArrayList<>();
    private StkTextLineToCenterAdapter adapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_turntable;
    }

    @Override
    protected void initView() {
        mDataBinding.ivTurntableBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivCustom.setOnClickListener(this);
        mDataBinding.ivStart.setOnClickListener(this);

        mDataBinding.turnTableContainer.setListener(new StkTurnTableView.IListener() {
            @Override
            public void onRotateStart() {
                //开始转动时的回调
            }

            @Override
            public void onRotateEnd() {
                //转动结束时的回调
            }

            @Override
            public void onSelItem(int pos) {
                //转动结束时，指针所指向的数据位置
                StkTurnTableItem item = (StkTurnTableItem) mDataBinding.turnTableContainer.getAdapter().getItem(pos);
            }
        });

        adapter = new StkTextLineToCenterAdapter();
        adapter.setTextHOffset(-20);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.ivCustom://自定义转盘
                startActivity(SetOptionActivity.class);
                break;
            case R.id.ivStart://开始
                //转动
                mDataBinding.turnTableContainer.startRotate();
                break;
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void getData() {
        listData.clear();
        List<String> listSp = AppSpUtils.getTurntableList();
        if (listSp != null && listSp.size() > 0) {
            StkTurnTableItem item;
            for (int i = 0; i < listSp.size(); i++) {
                item = new StkTurnTableItem();
                item.text = listSp.get(i);
                item.bgColor = i % 2 == 0 ? Color.parseColor("#F5FD7F") : Color.parseColor("#9ACD4A");
                item.textColor = Color.parseColor("#000000");
                item.textSize = SizeUtils.sp2px(12);
                listData.add(item);
            }
            adapter.setDataList(listData);
            mDataBinding.turnTableContainer.setAdapter(adapter);
        }
    }
}